//
//  JQFYSectionHeader.m
//  JQFY
//
//  Created by 代辉 on 2017/10/30.
//  Copyright © 2017年 yannis. All rights reserved.
//

#import "JQFYSectionHeader.h"

@interface JQFYSectionHeader ()

@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UIButton *clickMore;

@end
@implementation JQFYSectionHeader

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setupUI];
    }
    return self;
}
- (void)setupUI
{
    self.backgroundColor = [UIColor clearColor];
    self.titleLabel = [UILabel new];
    [self addSubview:self.titleLabel];
    self.titleLabel.font = [UIFont fontWithName:@"SourceHanSansCN-Medium" size:18];
    self.titleLabel.textColor = [UIColor colorWithHex:0x333333];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(15 *SCAL);
        make.centerY.equalTo(self);
    }];
    
    self.clickMore = [UIButton new];
    [self.clickMore setBackgroundImage:[UIImage imageNamed:@"click_more"] forState:UIControlStateNormal];
    self.clickMore.titleLabel.font = [UIFont systemFontOfSize:8];
    [self.clickMore setTitle:@"查看更多" forState:UIControlStateNormal];
    [self.clickMore setTintColor:[UIColor whiteColor]];
    [self addSubview:self.clickMore];
    [self.clickMore mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self);
        make.right.equalTo(self).offset(-15 *SCAL);
    }];
    [self.clickMore addTarget:self action:@selector(clickMore:) forControlEvents:UIControlEventTouchUpInside];
}
- (void)clickMore:(UIButton *)button
{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"clickMore" object:@(self.index)];
}
- (void)setTitle:(NSString *)title
{
    _title = title;
    self.titleLabel.text = title;
}

- (void)setIndex:(NSInteger)index
{
    _index = index;
    if (index == 1 || index == 3) {
        self.clickMore.hidden = YES;
    }
}
@end
